package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.EnterpriseEcosystem;
import com.fsnbigdata.domain.Enterprise;
import com.fsnbigdata.domain.QEnterpriseEcosystem;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = EnterpriseEcosystemRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = EnterpriseEcosystemRepositoryCustom.class)
@Transactional(readOnly = true)
public class EnterpriseEcosystemRepositoryImpl extends QueryDslRepositorySupportExt<EnterpriseEcosystem> implements EnterpriseEcosystemRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    EnterpriseEcosystemRepositoryImpl() {
        super(EnterpriseEcosystem.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ENTERPRISE = "enterprise";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ECOSYSTEM_ID = "ecosystemId";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String NAME = "name";

    /**
     * TODO Auto-generated method documentation
     *
     * @param enterprise
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<EnterpriseEcosystem> findByEnterprise(Enterprise enterprise, GlobalSearch globalSearch, Pageable pageable) {
        QEnterpriseEcosystem enterpriseEcosystem = QEnterpriseEcosystem.enterpriseEcosystem;
        JPQLQuery<EnterpriseEcosystem> query = from(enterpriseEcosystem);
        Assert.notNull(enterprise, "enterprise is required");
        query.where(enterpriseEcosystem.enterprise.eq(enterprise));
        Path<?>[] paths = new Path<?>[] { enterpriseEcosystem.enterprise, enterpriseEcosystem.ecosystemId, enterpriseEcosystem.name };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(ENTERPRISE, enterpriseEcosystem.enterprise).map(ECOSYSTEM_ID, enterpriseEcosystem.ecosystemId).map(NAME, enterpriseEcosystem.name);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, enterpriseEcosystem);
    }
}
